package com.basic.business.img.controller;


import java.util.List;
import java.io.IOException;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import com.basic.common.annotation.FileExport;
import com.basic.common.utils.easyExcel.EasyExcelUtils;
import org.springframework.web.bind.annotation.*;
import com.basic.common.annotation.Log;
import com.basic.common.core.controller.BaseController;
import com.basic.common.core.domain.AjaxResult;
import com.basic.common.enums.BusinessType;
import com.basic.business.img.domain.TImagesInfo;
import com.basic.business.img.service.ITImagesInfoService;
import com.basic.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 素材信息Controller
 * 
 * @author zhaoxy_jn@163.com
 */
@RestController
@RequestMapping("/business/imgInfo")
public class TImagesInfoController extends BaseController
{
    @Resource
    private ITImagesInfoService tImagesInfoService;

    /**
     * 查询素材信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:imgInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(TImagesInfo tImagesInfo)
    {
        startPage();
        List<TImagesInfo> list = tImagesInfoService.getList(tImagesInfo);
        return getDataTable(list);
    }

    /**
     * 导出素材信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:imgInfo:export')")
    @Log(title = "素材信息", businessType = BusinessType.EXPORT)
    @FileExport(fileName = "素材信息.xlsx")
    @GetMapping("/export")
    public String export(TImagesInfo tImagesInfo) throws IOException
    {
        List<TImagesInfo> list = tImagesInfoService.getList(tImagesInfo);
        return EasyExcelUtils.excelExport(TImagesInfo.class,"素材信息数据", list);
    }

    /**
     * 获取素材信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:imgInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tImagesInfoService.get(id));
    }

    /**
     * 新增素材信息
     */
    @Log(title = "素材信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TImagesInfo tImagesInfo)
    {
        return toAjax(tImagesInfoService.insert(tImagesInfo));
    }

    /**
     * 修改素材信息
     */
    @PreAuthorize("@ss.hasPermi('business:imgInfo:editInfo')")
    @Log(title = "素材信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TImagesInfo tImagesInfo)
    {
        return toAjax(tImagesInfoService.update(tImagesInfo));
    }

    /**
     * 删除素材信息
     */
    @PreAuthorize("@ss.hasPermi('business:imgInfo:remove')")
    @Log(title = "素材信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tImagesInfoService.deleteByIds(ids));
    }

    /**
     * 状态变更
     */
    @PreAuthorize("@ss.hasPermi('business:imgInfo:changeStatus')")
    @Log(title = "素材信息", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestParam("ids") String[] ids, @RequestParam("status") String status)
    {
        return toAjax(tImagesInfoService.updateStatusByIds(ids, status));
    }

    /**
     * 根据素材编码获取素材信息
     */
    @GetMapping("/getImgInfoByIds/{ids}")
    public TableDataInfo getImgInfoByIds(@PathVariable String[] ids)
    {
        List<TImagesInfo> list = tImagesInfoService.getImgInfoByIds(ids);
        return getDataTable(list);
    }

    /**
     * 根据文件md5和桶名称判断文件是否存在
     */
    @GetMapping("/isExistFile/{imgHash}")
    public AjaxResult isExistFile(@PathVariable("imgHash") String imgHash)
    {
        return success(tImagesInfoService.isExistFile(imgHash));
    }

    /**
     * TBIR接口
     */
    @PostMapping("/searchImage")
    public AjaxResult searchImage(MultipartFile file)
    {
        return tImagesInfoService.searchImage(file);
    }

    /**
     * 查询特征码成功失败个数
     */
    @GetMapping("/getVectorsCount")
    public AjaxResult getVectorsCount()
    {
        return success(tImagesInfoService.getVectorsCount());
    }


}
